﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace iStudio.Structure.Control.Audio.Equalizer
{
    public class EqualizerSlider : Slider
    {
        /// <summary>
        /// Identifies the <see cref="Frequency" /> dependency property. 
        /// </summary>
        /*public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(float), typeof(EqualizerSlider), new UIPropertyMetadata(0.0f, OnFrequencyChanged, OnCoerceFrequency));

        /// <summary>
        /// Gets or sets the frequency of the slider
        /// </summary>
        public float Frequency
        {
            // IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!
            get
            {
                return (float)GetValue(FrequencyProperty);
            }
            set
            {
                SetValue(FrequencyProperty, value);
            }
        }

        private static object OnCoerceFrequency(DependencyObject o, object value)
        {
            EqualizerSlider equalizerSlider = o as EqualizerSlider;
            if (equalizerSlider != null)
            {
                return equalizerSlider.OnCoerceFrequency((int)value);
            }
            return value;
        }

        private static void OnFrequencyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            EqualizerSlider equalizerSlider = o as EqualizerSlider;
            if (equalizerSlider != null)
            {
                equalizerSlider.OnFrequencyChanged((int)e.OldValue, (int)e.NewValue);
            }
        }

        /// <summary>
        /// Coerces the value of <see cref="Frequency"/> when a new value is applied.
        /// </summary>
        /// <param name="value">The value that was set on <see cref="Frequency"/></param>
        /// <returns>The adjusted value of <see cref="Frequency"/></returns>
        protected virtual int OnCoerceFrequency(int value)
        {
            value = Math.Max(1, value);
            return value;
        }

        /// <summary>
        /// Called after the <see cref="Frequency"/> value has changed.
        /// </summary>
        /// <param name="oldValue">The previous value of <see cref="Frequency"/></param>
        /// <param name="newValue">The new value of <see cref="Frequency"/></param>
        protected virtual void OnFrequencyChanged(int oldValue, int newValue)
        {
        }
        */

        public int Index
        {
            get;
            set;
        }
    }
}
